<template>
  <div class="container">
    <div class="content-head" style="margin-bottom: 20px;">
      <div class="sort-keys">
        <a-input placeholder="搜索用户名/手机号" style="width: 180px;margin-right:10px;" v-model="filter.key" allowClear/>
        <span style="margin-left: 20px; margin-right: 6px;">日期:</span>
        <IDatePicker :showTime="false" style="margin-left: 10px;" placeholder="不选则不限制" v-model="filter.min_day"></IDatePicker>
        至
        <IDatePicker :showTime="false" style="margin-left: 0px;" placeholder="不选则不限制" v-model="filter.max_day"></IDatePicker>
      </div>
    </div>
    <a-table class="table" :rowKey="row => row.id" :dataSource="list">
      <a-table-column title="领取日期" width="60px">
        <template slot-scope="row">
          <div>{{row.created_at}}</div>
        </template>
      </a-table-column>
      <a-table-column
        title="登陆用户"
        key="name"
        width="100px"
      >
        <template slot-scope="row">
          <span v-if="row.user">
            <img :src="row.user.headimg" class="headimg">
            {{ row.user.name }}
            <a-tag color="red" style="margin-left:10px;" v-if="row.user.status === 2">已拉黑</a-tag>
            <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_nopay === 1">禁付</a-tag>
          </span>
        </template>
      </a-table-column>
      <a-table-column title="手机" width="60px">
        <template slot-scope="row">
          <div v-if="row.user">{{row.user.phone}}</div>
        </template>
      </a-table-column>
      
    </a-table>


  </div>
</template>

<script>
  import { getTaskdayLogList } from '@/api/visitors'
  import moment from 'moment'
  import IDatePicker from "@/components/IDatePicker/IDatePicker.vue"

  export default {
    components: {
      IDatePicker
    },
    data() {
      return {
        info: {},
        list: [],
        filter: {
          key: '',
          min_day: '',
          max_day: ''
        }
      }
    },
    computed: {
    },
    props: {
      task_id: 0,
    },
    created() {
      this.fetchData();
    },
    filters: {
      formatDate (value) {
        return value ? moment(value).fromNow() : ''
      },
      formatDate2 (value) {
        return value ? moment(value).format('YYYY-MM-DD') : ''
      }
    },
    mounted() {},
    watch: {
      'filter.min_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.fetchData()
        }
      },
      'filter.max_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.fetchData()
        }
      },
      'filter.key'() {
        this.fetchData()
      },
    },
    methods: {
       fetchData () {
        getTaskdayLogList({
          task_id: this.task_id,
          key: this.filter.key,
          min_day: this.filter.min_day,
          max_day: this.filter.max_day,
        }).then(res => {
          this.list = res.data.list
        })
      },
      cancel() {
        this.$router.back(-1)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .headimg {
    width: 28px;
    height: 28px;
    border-radius: 50%;
  }


  .form-container {
    padding-bottom: 120px;
  }

  .container {
    .btn {
      margin-right: 30px;
    }
  }

  .tips-c {
    margin-bottom: 20px;
    font-weight: 500;
  }
</style>
